/*
 *   Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *   Licensed under the GNU General Public License v3 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *        http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *   under the License.
 */

package xperiment.metaphor.model.link;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import xperiment.metaphor.model.DomainObject;
import xperiment.metaphor.model.Persistent;
import xperiment.metaphor.model.XML;

/**
 * A link between two entities
 * @author Mark P Ashworth <javameme@gmail.com>
 * @version 1.0.0
 * @since 1.0.0
 */
public class Link extends DomainObject implements Persistent, XML {

    /* The unique database id for the object */
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "link_id", unique = true, nullable = false)
    private Long id = null;

    @Column(name = "owner_id", nullable=false)
    private Serializable owner;

    @Column(name = "subject_id", nullable=false)
    private Serializable subject;

    /** Whether the object is enabled */
    @Column(name = "enabled", nullable=true)
    private boolean enabled = true;

    /**
     * The unique database id for the object
     * @return long
     */
    public Long getId() {
        return id;
    }

    /**
     * Whether the object is enabled
     * @return boolean
     */
    public boolean isEnabled() {
        return this.enabled;
    }

    /**
     * Whether the object is enabled
     * @param enabled The new value
     */
    public void setEnabled(boolean enabled) {
        boolean old = this.enabled;
		this.enabled = enabled;
		firePropertyChange("enabled", old, this.enabled);
    }

    /**
     * Returns the XML representation of the link.<br />
     * @return String
     */
    public String toXML() {

        return "<link class='" + getClass().getName()
                + "' id='" + getId()
                + "' enabled='" + isEnabled()
                +"' >"
                + "</link>";
    }
}
